﻿<Page:BasePage
    x:Class="Tfs.OnTheRoad.MainPage"
    xmlns:Page="clr-namespace:Tfs.OnTheRoad.Pages"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:Mvvm="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP7"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    xmlns:Controls="clr-namespace:Tfs.OnTheRoad.Controls" ApplicationBarButtons="Refresh,About,Settings" 
    shell:SystemTray.IsVisible="True">

    <!--Enabling Page Transitions-->
    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Controls:HeaderControl Grid.Row="0" ProfileNameVisibility="Collapsed"></Controls:HeaderControl>
        <Grid Grid.Row="1" Margin="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <Image Source="/Images/ProfileIcon.png" Width="24" Margin="5" Grid.Column="0"></Image>
            <toolkit:ListPicker x:Name="profileListPicker" Grid.Column="1"  Margin="0" ItemsSource="{Binding Profiles}" >
                <Interactivity:Interaction.Triggers>
                    <Interactivity:EventTrigger EventName="SelectionChanged">
                        <Mvvm:EventToCommand Command="{Binding SelectProfile}" PassEventArgsToCommand="True">
                        </Mvvm:EventToCommand>
                    </Interactivity:EventTrigger>
                </Interactivity:Interaction.Triggers>
                <toolkit:ListPicker.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding ProfileName}"></TextBlock>
                    </DataTemplate>
                </toolkit:ListPicker.ItemTemplate>
            </toolkit:ListPicker>

            <Button Grid.Column="2" Padding="0" BorderThickness="0" Background="{StaticResource PhoneAccentBrush}">
                <Image Source="/Images/appbar.add.rest.png" Width="30" Margin="0"></Image>
                <Interactivity:Interaction.Triggers>
                    <Interactivity:EventTrigger EventName="Click">
                        <Mvvm:EventToCommand Command="{Binding AddProfile}"></Mvvm:EventToCommand>
                    </Interactivity:EventTrigger>
                </Interactivity:Interaction.Triggers>
            </Button>

            <Button Grid.Column="3" Padding="0" BorderThickness="0" Background="{StaticResource PhoneAccentBrush}">
                <Interactivity:Interaction.Triggers>
                    <Interactivity:EventTrigger EventName="Click">
                        <Mvvm:EventToCommand Command="{Binding RemoveProfile}"></Mvvm:EventToCommand>
                    </Interactivity:EventTrigger>
                </Interactivity:Interaction.Triggers>
                <Image Source="/Images/appbar.minus.rest.png" Width="30" Margin="0"></Image>
            </Button>            
        </Grid>
        <TextBlock Grid.Row="2"
                   Foreground="{StaticResource PhoneAccentBrush}" Style="{StaticResource PhoneTextTitle1Style}"  x:Name="PageTitle" 
                   Text="{Binding PageTitle}" Margin="9,-7,0,0" />
        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="3" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ListBox toolkit:TiltEffect.IsTiltEnabled="True" SelectionMode="Single" x:Name="ItemsListBox" Grid.Row="0" ItemsSource="{Binding Items,Mode=TwoWay}" Visibility="{Binding HasResults, Converter={StaticResource BooleanToVisibilityConverter}}">
                <Interactivity:Interaction.Triggers>
                    <Interactivity:EventTrigger EventName="SelectionChanged">
                        <Mvvm:EventToCommand Command="{Binding NavigateToProject}" PassEventArgsToCommand="True">
                        </Mvvm:EventToCommand>
                    </Interactivity:EventTrigger>
                </Interactivity:Interaction.Triggers>                
                <ListBox.Template>
                    <ControlTemplate TargetType="ListBox">
                        <ScrollViewer>
                            <StackPanel>
                                <ItemsPresenter/>
                                <HyperlinkButton Content="Load More ..." Margin="10" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="{Binding LoadMoreResultsVisible, Converter={StaticResource BooleanToVisibilityConverter}}" Style="{StaticResource HyperlinkButtonNotUnderlineStyle}" >
                                    <Interactivity:Interaction.Triggers>
                                        <Interactivity:EventTrigger EventName="Click">
                                            <Mvvm:EventToCommand Command="{Binding LoadMoreItems}"></Mvvm:EventToCommand>
                                        </Interactivity:EventTrigger> 
                                    </Interactivity:Interaction.Triggers>                                
                                </HyperlinkButton>
                            </StackPanel>
                        </ScrollViewer>
                    </ControlTemplate>
                </ListBox.Template>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,0,0,17" Width="432" Orientation="Horizontal">
                            <Image Width="28"  Source="Images\project.png"></Image>
                            <TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyleWithoutForeground}" />
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

            <TextBlock Grid.Row="0" Visibility="{Binding HasResults, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter=true}" Padding="10" TextWrapping="Wrap" FontSize="30" Text="{Binding NoResultsFoundMessage}"></TextBlock>
 
            <toolkit:PerformanceProgressBar Height="20" x:Name="SearchProgressBar" Grid.Row="1" IsIndeterminate="True" Visibility="{Binding IsSearching, Converter={StaticResource BooleanToVisibilityConverter}}" />

        </Grid>
    </Grid>
</Page:BasePage>